'use strict';

const Controller = require('egg').Controller;

class SearchController extends Controller {
  // 搜索用户
	async user(){
		const {ctx, app} = this
		ctx.validate({
			keyword: {
				type: 'string',
				required: true,
				desc: '关键字'
			}
		});
		let { keyword } = ctx.request.body
		// 通过关键字查数据库，不要字段password
		let data = await app.model.User.findOne({
			where: { username: keyword },
			attributes: { exclude: ['password'] }
		});
		ctx.apiSuccess(data)
		
	}
}

module.exports = SearchController;
